package me.huangxiang.data_structure_and_algorithm.common;

import java.io.*;

public class IntegerArrayLoader {
    public static int[] loadInteger() throws IOException {
        String filePath = System.getProperty("user.dir");
        filePath += File.separator;
        filePath += "data.txt";
        System.out.println("FilePath: " + filePath);

        File file = new File(filePath);
        if (!file.exists()){
            System.out.println("data.txt isn't existed.");
        }

        FileReader fr = new FileReader(file);
        BufferedReader br = new BufferedReader(fr);

        int[] integerArray = new int[100];
        String oneLine = null;
        int count = 0;
        while ((oneLine = br.readLine()) != null){
            integerArray[count] = Integer.valueOf(oneLine);
            count++;
        }
        System.out.println("Count: " + count);
        br.close();
        fr.close();
        return integerArray;
    }
    public static void main(String[] args) throws IOException {

        int[] allInteger = loadInteger();
        for (int i = 0; i < allInteger.length; i++){
            int one = allInteger[i];
            System.out.println(one);
        }

    }
}
